<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>三个数，求ax^2+bx+c=0的根,保留两位小数</title>
	</head>
	<body>
		<script type="text/javascript">
			let arr = [1, 2, -3]; //数字为1,2,-3;
			let a = arr[0];
			let b = arr[1];
			let c = arr[2];
			let x1, x2;
			function t() {
				let delta = b * b - 4 * a * c;
				if (delta > 0) { //2个不等实根
					let p = -b / (2 * a);
					let q = Math.sqrt(delta) / (2 * a);
					x1 = p + q;
					x2 = p - q;
					return {
						x1,
						x2
					};
				} else { //无实根
					return null;
				}
			}
			console.log(t());
		</script>
	</body>
</html>
